package interactor;

import context.*;
	
import mainFrame.DrawPanel;

import java.awt.Graphics2D;
import java.awt.image.ImageObserver;

import util.PixelPoint;
import util.Util2;

// ********************************************************************
// *** CLASS: MeasureInteractor
// ********************************************************************
public class MeasureInteractor extends Interactor implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  static final String TAG="interactor.MeasureInteractor";

  public String getMouseModeMnemonic() { return("Measure"); }
  private boolean measuring;

  // ******************************************************************
  // *** CONSTRUCTOR: MeasureInteractor
  // ******************************************************************
  public MeasureInteractor(DrawPanel drawPanel)
  { super(drawPanel,MEASURE); }

  // ******************************************************************
  // *** METHOD: paintMouseEffect
  // ******************************************************************
  public void paintMouseEffect(Graphics2D g,ImageObserver imageObserver)
  {	if(measuring) { Util2.drawLine(g,mouseStart,mouseCurrent); } }

  // ******************************************************************
  // *** METHOD: mouseDragged
  // ******************************************************************
  // Invoked when a mouse button is pressed and then dragged.
  protected void mouseDragged() { if(measuring) drawPanel.repaint(); }

  // ******************************************************************
  // *** METHOD: mouseMoved
  // ******************************************************************
  // Invoked when the mouse has been moved (with no buttons down).
  protected void mouseMoved() {}

  // ******************************************************************
  // *** METHOD: mousePressed
  // ******************************************************************
  // Invoked when a mouse button has been pressed.
  protected void mouseLeftPressed(PixelPoint p)
  { if(!measuring) { measuring=true; mouseStart=p; } }
  protected void mouseRightPressed(PixelPoint p) {}

  // ******************************************************************
  // *** METHOD: mouseReleased
  // ******************************************************************
  // Invoked when a mouse button has been released.
  protected void mouseLeftReleased(PixelPoint p)
  { measurementDone(mouseStart,p);
    measuring=false; drawPanel.repaint();
  }
  protected void mouseRightReleased(PixelPoint p) {}

}